<template>
  <div class="flex justify-center items-center global-search">
    <div class="flex search-input">
      <input v-model="kw" :placeholder="placeholder" @keydown.enter="search" @focus="onFocus" />
      <!-- <a-button size="large" status="danger" @click="refresh">
          {{ t["重置"] }}
        </a-button> -->
      <div class="search-button text-white flex justify-center items-center">
        <div class="px-4" @click="search">
          <IconSearch :size="16" />
        </div>
        <div class="px-4" @click="reset">
          <IconDelete :size="16" />
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
const emit = defineEmits(["search", "update:keyword", "reset", "onFocus"]);

const kw = ref("");
const props = defineProps<{
  keyword: string;
  placeholder?: string;
}>();
const reset = () => {
  kw.value = "";
  emit("reset");
};
const search = () => {
  emit("update:keyword", kw.value);
  emit("search", kw.value);
};

const onFocus = () => {
  emit("onFocus");
};
</script>

<style scoped lang="scss">
.search-input {
  position: relative;
  border-radius: 20px;
  overflow: hidden;

  &:hover {
    .search-button {
      opacity: 1;
    }
  }

  input {
    width: 400px;
    border: 2px solid #111;
    border-radius: 20px;
    color: #333;
    line-height: 36px;
    padding-left: 20px;
    font-size: 14px;
  }

  .search-button {
    position: absolute;
    width: fit-content;
    height: 100%;
    background-color: #111;
    right: 0;
    cursor: pointer;

    opacity: 0;

    &:hover {
      background-color: #333;
    }

    &:active {
      background-color: #666;
    }

    div {
      height: 100%;
      line-height: 40px;
      text-align: center;

      &:hover {
        background-color: rgb(73, 73, 73);
      }
    }
  }
}
</style>
